﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class sysadmin_CourseManager_ResourceCommentNew : PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    PowerCreator.LMS.Web.Comment.Comment opComment = new PowerCreator.LMS.Web.Comment.Comment();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["ResourceID"] = "0";
            if (Request.QueryString["ResourceID"] != null)
            {
                ViewState["ResourceID"] = Request.QueryString["ResourceID"].ToString();
            }
            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
        }
    }
    protected override void InitPage()
    {
        lbl_InfoTitle.Text = GetLanageValueByKey("ResourceComment_lbl_title", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_UserName.Text = GetLanageValueByKey("lbl_EditStudent_LoadingName", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_RealName.Text = GetLanageValueByKey("lbl_EditStudent_Name", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Title.Text = GetLanageValueByKey("ResourceComment_gv_c1", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Search.Text = GetLanageValueByKey("btn_Search", PowerCreator.LMS.Language.LanagetItemType.Page);

        base.InitPage();
    }
    private string GetSearch()
    {
        StringBuilder sbSearch = new StringBuilder();
        sbSearch.Append(string.Format(" ResourceID = {0} ", ViewState["ResourceID"]));
        if (!string.IsNullOrEmpty(txt_UserName.Text))
        {
            sbSearch.Append(string.Format(" and CreatedUserName like '%{0}%'", txt_UserName.Text));
        }
        if (!string.IsNullOrEmpty(txt_RealName.Text))
        {
            sbSearch.Append(string.Format(" and CreatedRealName like '%{0}%'", txt_RealName.Text));
        }
        if (!string.IsNullOrEmpty(txt_Title.Text))
        {
            sbSearch.Append(string.Format(" and Title like '%{0}%'", txt_Title.Text));
        }
        return sbSearch.ToString();
    }

    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = opComment.QueryCommentCount(search);
        AspNetPager1.PageSize = LMSPageSize;
    }

    private void BinderRPT(string search,int pageIndex)
    {
        string orderList = "";
        DataTable dt = opComment.QueryComment(search, orderList, PowerCreator.LMS.Web.Config.WebConfig.PageSize, pageIndex);
        rpt_Comment.DataSource = dt;
        rpt_Comment.DataBind();
        PreAspNetPager(AspNetPager1);
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderRPT(search, 1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rpt_Comment_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "lauditing")
        {
            PowerCreator.LMS.Comment.Entity.VOSysPLCommentInfo voComment = opComment.LoadComment(int.Parse(e.CommandArgument.ToString()));
            if (voComment.CommentID > 0)
            {
                if (voComment.IsShow == int.MinValue)
                    voComment.IsShow = 0;

                voComment.IsShow += 1;
                if (voComment.IsShow >= 2)
                {
                    voComment.IsShow = 0;
                }

                if (opComment.UpdataComment(voComment))
                {
                    string search = GetSearch();
                    BinderRPT(search, AspNetPager1.CurrentPageIndex);
                }
                else
                {
                    Label lbl_rpt_msg = (Label)e.Item.FindControl("lbl_rpt_msg");
                    //lbl_rpt_msg.Text = "审核出现更新异常!请联系管理员!";
                    lbl_rpt_msg.Text = GetLanageValueByKey("ResourceComment_msg_m1", PowerCreator.LMS.Language.LanagetItemType.Page);
                }
            }
        }
        else if (e.CommandName == "ldel")
        {
            if (opComment.DelComment(int.Parse(e.CommandArgument.ToString())))
            {
                string search = GetSearch();
                BinderPager(search);
                BinderRPT(search, AspNetPager1.CurrentPageIndex);
            }
            else
            {
                Label lbl_rpt_msg = (Label)e.Item.FindControl("lbl_rpt_msg");
                //lbl_rpt_msg.Text = "删除数据出现异常!请联系管理员!";
                lbl_rpt_msg.Text = GetLanageValueByKey("ResourceComment_msg_m2", PowerCreator.LMS.Language.LanagetItemType.Page);
            }
        }
    }
}
